package com.supermap.dataservice.cloud.circum;

import com.supermap.dataservice.util.JSONUtil;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Map;

/**
 * @author aqua
 * @description
 * @date 2018年11月19 下午 8:43
 * @email 1301584033@qq.com
 */
@Mapper
public interface CropsHospitalMapper {


    /**
     * 庄稼医院查询
     * */
    @SelectProvider(type = CropsHospitalMapperSQL.class,method = "getPageCropsHospitalByAreaCodeOrkeyName")
    List<Map<String,Object>> getPageCropsHospitalByAreaCodeOrkeyName(@Param("areaCode") String areaCode,@Param("keyName") String keyName,@Param("pageNum")Integer pageNum,@Param("pageSize")Integer pageSize);

    @SelectProvider(type = CropsHospitalMapperSQL.class,method = "getPageCropsHospitalByAreaCodeOrkeyNameCount")
    int getPageCropsHospitalByAreaCodeOrkeyNameCount(@Param("areaCode") String areaCode,@Param("keyName") String keyName);


    class  CropsHospitalMapperSQL{
        public String getPageCropsHospitalByAreaCodeOrkeyName(Map<String,Object> map){
            String areaCode=(String)map.get("areaCode");
            String keyName=(String)map.get("keyName");
            int pageNum=(int)map.get("pageNum");
            int pageSize=(int)map.get("pageSize");
            StringBuilder stringBuilder=new StringBuilder();
            stringBuilder.append("select t1.id,t1.areacode,t2.areaname,t1.hospital_name,\n" +
                    "t1.mailnum,t1.tel,t1.url,t1.charge,t1.address,t1.lon,t1.lat from t_suply_yy t1 Left join  t_area t2 on t1.areacode=t2.areacode \n" +
                    "where 1=1 ");
            if(areaCode!=null){
                stringBuilder.append(" and t1.areacode like concat("+areaCode+",'%')" );
            }
            if(keyName!=null){
                stringBuilder.append(" and (t1.hospital_name like concat('%','"+keyName+"','%')  or t1.address like concat('%','"+keyName+"','%')) ");
            }
            stringBuilder.append(" limit "+pageNum+","+pageSize+"");
            return  stringBuilder.toString();
        }
        public String getPageCropsHospitalByAreaCodeOrkeyNameCount(Map<String,Object> map){
            String areaCode=(String)map.get("areaCode");
            String keyName=(String)map.get("keyName");
            StringBuilder stringBuilder=new StringBuilder();
            stringBuilder.append("select count(1) from t_suply_yy t1 Left join  t_area t2 on t1.areacode=t2.areacode \n" +
                    "where 1=1 ");
            if(areaCode!=null){
                stringBuilder.append(" and t1.areacode like concat("+areaCode+",'%')" );
            }
            if(keyName!=null){
                stringBuilder.append(" and (t1.hospital_name like concat('%','"+keyName+"','%')  or t1.address like concat('%','"+keyName+"','%')) ");
            }
            return  stringBuilder.toString();
        }
    }
}
